package com.zwjlg.aroutemoduleservice;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.launcher.ARouter;
import com.zwjlg.baselibrary.ARouterConstants;
import com.zwjlg.baselibrary.HotFix;
import com.zwjlg.baselibrary.HotFixEngine;
import com.zwjlg.module_other.service.OtherService;
import com.zwjlg.module_user.service.UserInfoService;

//import hugo.weaving.DebugLog;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    @Autowired
    OtherService otherService;
    @Autowired
    UserInfoService userInfoService;
    TextView tvMessage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ARouter.getInstance().inject(this);
        setContentView(R.layout.activity_main);
        tvMessage = findViewById(R.id.tv_message_app);
        findViewById(R.id.btn1).setOnClickListener(this);
        findViewById(R.id.btn2).setOnClickListener(this);
        findViewById(R.id.btn3).setOnClickListener(this);
        findViewById(R.id.btn4).setOnClickListener(this);
    }

    //    @DebugLog
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn1:
                ARouter.getInstance().build(ARouterConstants.Activitys.OTHER_MAIN).navigation();
                break;
            case R.id.btn2:
                ARouter.getInstance().build(ARouterConstants.Activitys.USER_MAIN).navigation();
                break;
            case R.id.btn3:
                tvMessage.setText(tvMessage.getText() + "\n" + otherService.getKey());
                tvMessage.append("\n" + DebugClass.read());

                try {
                    Class c = Class.forName("com.lg.hack.FromDexFragment");
                    Object o = c.newInstance();
                    Fragment fragment = (Fragment) o;
                    getSupportFragmentManager().beginTransaction()
                            .add(R.id.rootView,fragment).commit();
                }catch (Exception ee){

                }
                break;
            case R.id.btn4:
                tvMessage.setText(tvMessage.getText() + "\n" + userInfoService.getUser().getName());
                HotFixEngine.copyDexFileToAppAndFix(this, "hack.dex", true);
//                HotFix.getInstance().injectHack("hack.dex");
//                HotFix.getInstance().injectHack("hacker2.dex");

                ClassLoader classLoader = getClassLoader();

                break;
        }
    }
}